import BaseChannel from "../base/BaseChannel";
import WXLogin from "./WXLogin";
import WXBanner from "./WXBanner";
import WXVideoAd from "./WXVideoAd";
import WXShare from "./WXShare";
import LayaExchangeVolume from "./LayaExchangeVolume";
import WXInterstitialAd from "./WXInterstitialAd";
import GameProxy from "../../proxy/GameProxy";
import Protocals from "../../proxy/Protocals";
import StringHelper from "../../framework/tools/StringHelper";
import { FOLLOW_REWARD_NUM } from "../../game/config/Const";
import ReceiveMessage from "../../framework/net/message/ReceiveMessage";
import ToastController from "../../game/public/toast/ToastController";
import GlobalEvent from "../../framework/event/GlobalEvent";
export default class WXChannel extends BaseChannel {

    private urls: string[] = ['https://www.sarsgame.com/games/gongzhonghao.jpg', 'https://www.sarsgame.com/games/tuchuchongwei.jpg']

    private isCheck: boolean = false

    constructor(id) {
        super(id)
        this.loginMgr = new WXLogin();
        this.bannerAd = new WXBanner('adunit');
        this.rewardAd = new WXVideoAd('adunit');
        this.exchagneVolume = new LayaExchangeVolume()
        this.share = new WXShare();
        this.interstitialAd = new WXInterstitialAd()
        GameProxy.getInstance().addEventListener(Protocals.FOLLOW_REWARD, this.onFollowRewardRes, this)
     
    }

    onFollowRewardRes(msg: ReceiveMessage) {
        if (!msg.isError()) {
            ToastController.instance().intoLayer('ui.follow_reward', { num: StringHelper.getShortStr(FOLLOW_REWARD_NUM) })
        }

    }

    intoLobby() {
        if (this.isCheck) {
            return;
        }
        this.isCheck = true;
        GlobalEvent.instance().addEventListener(GlobalEvent.EVENT_SHOW, this.check, this)
        this.check()
    }

    check() {
        let loginInfo = wx.getLaunchOptionsSync()
        if (loginInfo) {
            console.log('loginInfo.scene ' + loginInfo.scene)
            // ToastController.instance().show("场景值： "+loginInfo.scene+' ticket '+loginInfo.shareTicket)
            switch (loginInfo.scene) {
                case 1035://公众号
                    GameProxy.getInstance().sendMessage(Protocals.FOLLOW_REWARD, {})
                    break;
            }
            //   SDKManager.getChannel().getShare().getShareInfo(loginInfo,()=>{

            //   })
        }


    }


    showImage(imgUrl: string) {
        wx.previewImage({
            current: imgUrl, // 当前显示图片的http链接
            urls: [imgUrl] // 需要预览的图片http链接列表
        })
    }

    jumpToApp(appID: string) {
        wx.navigateToMiniProgram({
            appId: appID,
            success: () => {

            }
        })
    }
    /**
     * 显示商城 如果没有不重写
     */
    showStore() {
        this.rewardAd.show((isFinish: boolean) => {
            if (isFinish) {

            } else {

            }
        })
    }

    freeRevive() {
        this.rewardAd.show((isFinish: boolean) => {
            if (isFinish) {

            } else {

            }
        })
    }
}
